public class CountSegment {
    public static  int countSegment(String s) {
        s = s.trim();

        //处理空串
        if(s.isEmpty()) {
            return 0;
        }

        String[] strings = s.split(" ");

        int count = 0;
        for (String string : strings) {
             if(!string.isEmpty()) {
                 count++;
             }
        }

        return count;
    }

    public static void main(String[] args) {

    }
}
